package com.ycsj.goldmedalnewconcept.teacher.adapter;


import android.content.Context;
import android.support.annotation.Nullable;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ycsj.common.view.scroll.MyGridView;
import com.ycsj.goldmedalnewconcept.R;
import com.ycsj.goldmedalnewconcept.teacher.bean.SearchInfo;
import com.ycsj.goldmedalnewconcept.teacher.bean.SearchItem;

import java.util.List;

/**
 * 按条件筛选的列表适配器
 * Created by Administrator on 2019/2/22 0022.
 */

public class SearchRvAdapter extends BaseQuickAdapter<SearchInfo, BaseViewHolder> {

    private Context context;
    private List<SearchInfo> datas;
    private List<SearchItem> unitDatas;

    public SearchRvAdapter(Context context, int layoutResId, @Nullable List<SearchInfo> data, List<SearchItem> unitDatas) {
        super(layoutResId, data);
        this.context = context;
        this.datas = data;
        this.unitDatas = unitDatas;
    }

    @Override
    protected void convert(BaseViewHolder helper, final SearchInfo item) {
        //类型
        TextView tvType = helper.getView(R.id.tv_type);
        tvType.setText(item.searchName);

        //展示选项的GridView
        MyGridView mgv = helper.getView(R.id.mgv);
        SearchGvAdapter gvAdapter = new SearchGvAdapter(context, item.searachItems, R.layout.item_gv_search, datas, helper.getLayoutPosition());
        mgv.setAdapter(gvAdapter);
        gvAdapter.setOnUnitChooseListener(new SearchGvAdapter.OnUnitChooseListener() {
            @Override
            public void onUnitChoosed(SearchItem searchItem) {

                for (int i = 0; i < unitDatas.size(); i++) {


                    if (unitDatas.get(i) == searchItem) {
                        unitDatas.get(i).isChoosed = true;

                    } else {
                        unitDatas.get(i).isChoosed = false;
                    }
                }


                notifyDataSetChanged();
            }
        });
    }
}
